package module.building.view.produceweapon
{
	import code.analyze.ConfigAnalyze;
	
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.List;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.events.UIEvent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	
	import flash.display.Sprite;
	
	import main.AppControllerList;
	
	import module.building.model.dataObj.EquipObj;
	import module.edittroop.view.troopinfopanel.HeadFarem;
	import module.main.view.ResourceConst;

	public class EquipInfoItem extends UIComponent
	{
		/**
		 *武器名称 
		 */		
		private var _weaponName:Label;
		/**
		 *武力 
		 */		
		private var _weaponForce:Label;
		private var _weaponForceNum:int;
		/**
		 *防御 
		 */		
		private var _defenceLabel:Label;
		private var _defenceNum:int;
		/**
		 *技能 
		 */		
		private var _skillLabel:Label;
		private var _skillStr:String;
		/**
		 *武器相框 
		 */		
		private var _headFream:HeadFarem;
		private var _weaponList:List;
		private var _weaponInfoBg:UIComponent;
		/**
		 *数据强类型数组 
		 */		
		private var _arr:Array;
		public function EquipInfoItem(arr:Array)
		{
			_weaponName = new Label();
			_weaponForce = new Label();
			_defenceLabel = new Label();
			_skillLabel = new Label();
			_headFream = new HeadFarem();
			_weaponList = new List(HeadFarem,53,54,5);
			_weaponInfoBg = new UIComponent();
			_arr = arr;
			initView();
		}

		/**
		 * 武器列表
		 */
		public function get weaponList():List
		{
			return _weaponList;
		}

		/**
		 * @private
		 */
		public function set weaponList(value:List):void
		{
			_weaponList = value;
		}

		private function initView():void
		{
			_weaponForce.text = "武力 : ";
			_defenceLabel.text = "防御 : ";
			_skillLabel.text = "技能 : ";
			_weaponInfoBg.backgroundSkin = "EditTroop." + ResourceConst.EDIT_TROOP_SOLDIER_INFO_BG;
			_weaponInfoBg.width = 376.6;
			_weaponInfoBg.height = 129.9;
			this.width = _weaponInfoBg.width;
			this.height = _weaponInfoBg.height;
			this.addChild(_weaponInfoBg);
			setHeadFream();
			setLabelPosition();
			setListPostion();
		}
		private function setLabelPosition():void
		{
			///武器名称
			_weaponName.x = _headFream.x + _headFream.width + 15;
			_weaponName.y = _headFream.y;
			this.addChild(_weaponName);
			
			///武力
			_weaponForce.x = _weaponName.x - 20;
			_weaponForce.y = _weaponName.y + 20;
			this.addChild(_weaponForce);
			
			//防御力
			_defenceLabel.x = _weaponForce.x;
			_defenceLabel.y = _weaponForce.y + _weaponForce.height;
			this.addChild(_defenceLabel);
			
			//技能
			_skillLabel.x = _defenceLabel.x;
			_skillLabel.y = _defenceLabel.y  +_defenceLabel.height ;
			this.addChild(_skillLabel);
		}
		private function setListPostion():void
		{
			_weaponList.height = 113;
			_weaponList.width = 53*3 + 10;
			_weaponList.x = 190;
			_weaponList.y = _headFream.y - 5;
			_weaponList.source = _arr;
			addChild(_weaponList);
			_weaponList.addEventListener(UIEvent.LISTITEM_CLICK,clickHandler);
		}
		private function clickHandler(e:UIEvent):void
		{
			changgeData((e.data as HeadFarem).data);
		}
		private function setHeadFream():void
		{
			_headFream.data = _arr[0];
			_headFream.height = 82;
			_headFream.width = 74;
			_headFream.x = 17;
			_headFream.y = 17;
			this.addChild(_headFream);
		}
		public function changgeData(data:Object):void
		{
			var obj:EquipObj = data as EquipObj;
			_weaponName.text = obj.eqipName;
			
			_weaponForceNum = obj.attack;
			_weaponForce.text = "武力 : " + _weaponForceNum.toString();
			
			_defenceNum = obj.defence;
			_defenceLabel.text = "防御 : " + _defenceNum.toString();
			
			_weaponName.text = obj.name;
			/*_skillLabel = obj.skillList*/
		}
	}
}